const mongoose = require('mongoose')
const CommentSchema = new mongoose.Schema({
    body:String,
    author:{type:mongoose.Schema.Types.ObjectId,ref:'User'},
    article:{type:mongoose.Schema.Types.ObjectId,ref:'Article'},
    },{timestamp:true})
CommentSchema.methods.toJSONFor = function(user){
    return{
        id:this._id,
        body:this.body,
        createAt:this.createAt,
        author:this.author.toProfileJSONFFor(user)
    }
}
module.exports = 
mongoose.models.Comment ||  mongoose.model('Comment', CommentSchema);